class Solution:
    def intersect(self, nums1, nums2):
        hash1 = {}
        for i in nums1:
            if i not in hash1:
                hash1[i] = 0
            hash1[i] = hash1[i] + 1
        re = []
        for i in nums2:
            if i in hash1:
                re.append(i)
                if hash1[i] == 1:
                    hash1.pop(i)
                else:
                    hash1[i] = hash1[i] - 1
        return re

if __name__ == '__main__':
    so = Solution()
    nums1 = [1,2,2,1]
    nums2 = [2,2,1]
    r = so.intersect(nums1, nums2)
    print(r)
